pluginHome = new File("./plugins").listFiles().find { it.name.startsWith('cloud-tools-')}
if(pluginHome == null) pluginHome = "."

includeTargets << new File( "${pluginHome}/scripts/CloudToolsInit.groovy" )

target('default': "Enales the BRB Page") {
	updateWar()
}

target(updateWar: "The implementation task") {
	depends( initCloudToolsService)
    cloudToolsService.withCluster {clusterManager, clusterName, cluster ->
		if(System.getProperty("cloudtools.s3.path") != null && System.getProperty("cloudtools.path") != null){
        	cluster.getClusterInstance().getAppServerTier().updateWar(System.getProperty("cloudtools.path"), System.getProperty("cloudtools.s3.path"));
			event('StatusFinal', ['War updated'])
		}else{
			event('StatusError', ['You need to specify cloudtools.s3.path and cloudtools.path. Example:\ngrails -Dcloudtools.s3.path=<s3path> -Dcloudtools.path=<path> cloud-tools-update-war'])
		}
    }
}
